package com.easysoft.framework.casereply.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.casereply.mapper.SysCasemanagementMapperExtd;
import com.easysoft.framework.casereply.model.SysCasemanagement;
import com.easysoft.framework.casereply.model.SysCasemanagementQuery;
import com.easysoft.framework.casereply.model.SysCasemanagementView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by try on 2017/8/22.
 */
@Service("service.SysCasemanagementService")
public class SysCasemanagementService {

    @Autowired
    @Qualifier("mapper.SysCasemanagementMapperExtd")
    private SysCasemanagementMapperExtd sysCasemanagementMapperExtd;

    @DataSource(DataSource.MASTER)
    public int addSysCasemanagement(SysCasemanagement sysCasemanagement){
        sysCasemanagement.setId(UUIDUtils.getUUID());
        return sysCasemanagementMapperExtd.insertSelective(sysCasemanagement);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysCasemanagement(String id){
        return sysCasemanagementMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysCasemanagement(SysCasemanagement sysCasemanagement){
        return sysCasemanagementMapperExtd.updateByPrimaryKeySelective(sysCasemanagement);
    }

    public SysCasemanagement selectSysCasemanagementById(String id){
        return sysCasemanagementMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.SLAVE)
    public List<SysCasemanagementView> selectSysCasemanagementListByPage(SysCasemanagementQuery query, Page page){
        int maxRow = sysCasemanagementMapperExtd.selectCountSysCasemanagement(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysCasemanagementView>();
        }
        return sysCasemanagementMapperExtd.selectSysCasemanagementListByPage(query,page);
    }
}
